package com.example.manager.mapper;

import com.example.manager.entity.Book;
import com.example.manager.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("insert into user(username, password, admin) values (#{username},#{password},0)")
    Integer insert(User user);

    @Select("select * from user where username = #{username}")
    User findByUsername(String Username);

    @Select("select * from user where username like '%${search}%'")
    List<User> findUserByUsername(String search);
    @Select("select * from user where username = #{username} and password = #{password}")
    User login(@Param("username") String username,@Param("password") String password);

    @Select("select count(*) from user ")
    Integer getAllUserSize();

    @Select("select count(*) from user where username like '%${search}%'")
    Integer getAllUserSize1(String search);

    @Select("select * from user limit #{currentpage}, #{pageSize}")
    List<User> getUserByPage(@Param("currentpage")Integer currentpage,@Param("pageSize") Integer pageSize);

    @Select("delete from user where username=#{username}")
    void delUser(@Param("username") String username);

    @Update("update user set name = #{name},sex = #{sex},birth = #{birth},address = #{address},telephone = #{telephone} where username=#{username}")
    void updateUserInfo(User user);

    @Update("update user set password = #{newpassword} where username=#{username}")
    void updatepw(String username,String password,String newpassword);
}

